<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
    <!-- Google Chrome Frame也可以让IE用上Chrome的引擎: -->
    <meta name="renderer" content="webkit">
    <!--国产浏览器高速模式-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>作业管理系统</title>

    <!-- 公共样式 开始 -->
    <link rel="stylesheet" type="text/css" href="../../css/base.css">
    <link rel="stylesheet" type="text/css" href="../../css/iconfont.css">
    <script type="text/javascript" src="../../framework/jquery-1.11.3.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css">
    <script type="text/javascript" src="../../layui/layui.js"></script>
    <!-- 滚动条插件 -->
    <link rel="stylesheet" type="text/css" href="../../css/jquery.mCustomScrollbar.css">
    <script src="../../framework/jquery-ui-1.10.4.min.js"></script>
    <script src="../../framework/jquery.mousewheel.min.js"></script>
    <script src="../../framework/jquery.mCustomScrollbar.min.js"></script>
    <script src="../../framework/cframe.js"></script><!-- 仅供所有子页面使用 -->
    <!-- 公共样式 结束 -->
    <script type="text/javascript" src="../../framework/frameAll.js"></script>

    <style>
        .layui-form {
            margin-right: 30%;
        }

        .layui-form-label {
            width: 100px;
        }

        .layui-input-block {
            margin-left: 130px;
        }
    </style>
    <script type="text/javascript">
        var id = hrefByGet('id'),
            title = hrefByGet('title'),
            adminName = hrefByGet('adminName'),
            content = hrefByGet('content'),
            action = 'add';
        $(function () {
            if (id) {
                action = 'update';
            }
            if (title) {
                $('input[name=title]').val(title);
            }
            if (adminName) {
                $('input[name=adminName]').val(adminName);
            } else {
                $.ajax({
                    type: "get",
                    url: "/UserServlet.do",
                    data: {action: "getUser"},
                    dataType: "Json",
                    success: function (data) {
                        if (data.user) {
                            $("input[name=adminName]").val(data.user.name);
                        }
                    },
            });
        }
        if (content) {
            $('textarea[name=content]').text(content);
        }
        })
        ;
    </script>
</head>

<body>
<div class="cBody">
    <form id="addForm" class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" required lay-verify="required" placeholder="请输入标题"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">发布人</label>
            <div class="layui-input-inline shortInput">
                <input type="text" name="adminName" autocomplete="off" class="layui-input" readOnly="true">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">文本编辑器</label>
            <div class="layui-input-block">
                <textarea id="content" name="content" style="display: none;"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submitBut">立即提交</button>
                <button type="button" class="layui-btn layui-btn-primary" id="reset">重置</button>
            </div>
        </div>
    </form>

    <script>
        layui.use(['form', 'layedit'], function () {
            var form = layui.form;
            var layedit = layui.layedit;
            var index;
            $('#reset').click(function () {
                $('input[name=title]').val('');
                layedit.setContent(index, '');
            });


            index = layedit.build('content', {
                tool: [
                    'strong', //加粗 'italic' //斜体
                    'underline', //下划线
                    'del', //删除线
                    '|', //分割线
                    'left', //左对齐
                    'center', //居中对齐
                    'right', //右对齐
                    '|', //分割线
                    'link', //超链接
                    'unlink' //清除链接
                ]
            }); //建立编辑器
            //监听提交
            form.on('submit(submitBut)', function (data) {
                if (layedit.getText(index)) {
                    var data = {
                        action: action,
                        id: id,
                        title: data.field.title,
                        content: layedit.getContent(index)
                    };
                    $.ajax({
                        type: "post",
                        url: "/NoticeServlet.do",
                        data: data,
                        dataType: "Json",
                        success: function (data) {
                            if (data.tip) {
                                yesMsg(data.msg);
                                location.href = 'ggagent_list.html';
                            } else {
                                noMsg(data.msg);
                            }
                        }
                    });
                } else {
                    noMsg('必选项不能为空');
                }
                return false;
            });
        });
    </script>
</div>
</body>

</html>